package calbs.socket.packaging;/**
 * Created by zhangqin on 2017/8/11.
 */

import calbs.socket.pojo.resp.RespBaseMsg;
import calbs.socket.pojo.resp.RespData;
import calbs.socket.tool.Byte2Hex;
import calbs.socket.tool.CHexConver;
import calbs.socket.tool.CountNumber;
import calbs.socket.tool.XorTool;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author
 * @create 2017-08-11 16:29
 **/
public  class PackingUtils{
   private static CountNumber frameNumberSerial = new CountNumber();
    public static String packing(RespBaseMsg respBaseMsg,String content){
        if(StringUtils.isBlank(content)){
            content="";

        }
        StringBuffer buffer =new StringBuffer("7E7D");
        buffer.append(respBaseMsg.getFrameNumber());
        buffer.append(CHexConver.integeroHexString(frameNumberSerial.getNumber(),2));
        buffer.append(CHexConver.integeroHexString(content.length()/2,2));
        buffer.append(Byte2Hex.Bytes2HexString(new byte[]{XorTool.getXor(CHexConver.hexStr2Bytes(content))}));
        buffer.append(content);
        buffer.append("7E7D");
        return buffer.toString();
    }


    public static void main(String[] args) {
        byte[] i = {-1};
        System.out.println(Byte2Hex.Bytes2HexString(i));
    }
}
